import { Component, OnInit, Output, EventEmitter, Input, ViewEncapsulation } from '@angular/core';
import { DateOptionService } from 'app/share/date-option.service';
import { FormatDate } from 'app/classes/Device';

@Component({
  selector: 'app-time-picker',
  templateUrl: './time-picker.component.html',
  styleUrls: ['./time-picker.component.css'],
  encapsulation: ViewEncapsulation.None

})
export class TimePickerComponent implements OnInit {
  @Output()
  emitTime = new EventEmitter<TimePicker>();

  starttime: Date;
  endtime: Date;

  timepickerToOpts: object;
  constructor(
    public dateOption: DateOptionService
  ) { }

  ngOnInit() {
    this.timepickerToOpts = this.dateOption.getTimeOptions();
  }

  start(e) {
    if ( e ) {
      const timePicker = new TimePicker;
      timePicker.timeType = 'start';
      timePicker.timeValue = new FormatDate(e).getTime();
      this.emitTime.emit(timePicker);
    }
  }

  end(e) {
    if ( e ) {
      const timePicker = new TimePicker;
      timePicker.timeType = 'end';
      timePicker.timeValue = new FormatDate(e).getTime();
      this.emitTime.emit(timePicker);
    }
  }
  clear() {
    this.starttime = null;
    this.endtime = null;
  }
}

export class TimePicker {
  timeType: string;
  timeValue: string;
}
